import { ComponentType, lazy, Suspense } from "react";

const scenes = import.meta.glob<{ default: ComponentType }>(
  "@/models/scenes/*.tsx"
);

// 懒加载路由
export const autoRoutes = Object.keys(scenes).map((path) => {
  const name = path.substring(path.lastIndexOf("/"), path.lastIndexOf("."));
  const Component = lazy(scenes[path]);
  return {
    path: name.replace("index", ""),
    element: (
      <Suspense fallback={<div>Loading...</div>}>
        <Component />
      </Suspense>
    ),
  };
});
